home *** CD-ROM | disk | FTP | other *** search
/ WINMX Assorted Textfiles / Ebooks.tar / Text - Tech - Electronics - Schematics - DS1820 - Thermometer and Thermostat (HTML TXT).zip / D1820.TXT < prev    next >
Text File  |  1996-03-12  |  14KB  |  280 lines

  1.  
  2. Thermometer Interface Subsystem 
  3.  
  4. Daniel G. Clemmensen
  5.  
  6. This interface connects one or more Dallas 1820 thermometers to a BASIC STAMP.
  7. It is designed to connect other "one-wire" devices also, but this has not yet
  8. been tested. The 1820 is a three-pin device. Two pins are power and ground. 
  9. The third pin is used for serial communications using the Dallas "one-wire" 
  10. protocol. The thermometers all connect in parallel to this multidrop serial
  11. interface. The 1820 protocol requires some signal timing that cannot be 
  12. implemented purely in STAMP software. Therefore, the interface subsystem 
  13. includes a one-shot (yuck!), a latch, and a tri-state buffer. In conjunction 
  14. with the appropriate software, this circuit permits the STAMP to run the 
  15. protocol. The stamp interfaces to the circuit with two I/O pins.
  16.  
  17. The 1820 can operate with only two wires instead of three, by taking power 
  18. from its signaling lead. Dallas refers to this mode as "parasite power" mode.
  19. To use it, the master must drive several milliamps at +5VDC into the data line
  20. at certain times during certain operations. The circuit and the software do not
  21. provide this mode of operation, but can easily be adapted for it. This mode 
  22. will require three Stamp I/O pins.
  23.  
  24. Thermometer Interface Design 
  25.  
  26. The thermometer interface is intended to permit the stamp to control a multi-
  27. dropped "one wire" interface. Each thermometer's serial connection is open-
  28. drain. The interface pulls the wire up with a 5k resistor. The stamp and the
  29. thermometers communicate by pulling the wire low to send pulses. The stamp is
  30. the master. A thermometer sends a pulse only when the stamp tells it to. The
  31. protocol calls for the master to send pulses of several different lengths. 
  32. There is no maximum time between these pulses from the stamp. The length of 
  33. the pulse is significant, but the stamp hardware and software can send the 
  34. required pulses. The only hard part is reading the pulses sent from the 
  35. devices.
  36.  
  37. The stamp solicits a pulse from a device by sending a series of pulses ending 
  38. in a "read" pulse. To send back a "1", the device does nothing. To send back a
  39. "0", the device begins to pull the line down within one microsecond of 
  40. receiving the leading edge of the read pulse, and continues to hold the line 
  41. down for at least 15 microseconds. To read this response properly, the master's
  42. read pulse should be as short as possible, (nominally one microsecond), and the
  43. master should sample the wire about 14 microseconds after the leading edge of 
  44. the pulse.
  45.  
  46. The stamp's pulse timer granularity is 2 microseconds, and there is no obvious 
  47. way to program an output which signals both the one microsecond interval and 
  48. the 15 microsecond interval. Thus, an external timer is needed. and we are 
  49. forced into using a one-shot. Further, although the stamp's I/O pins are tri-
  50. statable,they cannot be turned around fast enough for the read. We use a tri-
  51. state buffer to solve this problem. Finally, we cannot actually read the input
  52. fast enough with the stamp. We solve this problem with a latch. There is 
  53. probably an elegant single-chip solution to this problem, but this circuit uses
  54. a three-chip brute-force approach.
  55.  
  56. The interface hardware and software cannot send a 1 microsecond pulse, so it 
  57. makes do with a 2 microsecond pulse. This cuts into the "guard time" during 
  58. which the one-wire is being pulled up by the pull-up resistor. The "guard time"
  59. is reduced from 13 microseconds to 12 microseconds. However, unless the one-
  60. wire has a large effective capacitance, (for example, if it's very long) there
  61. is no problem with this. It reduces the maximum cable length by less than ten 
  62. percent. I have not determined the maximum cable length, but I guess that it 
  63. will be on the order of one hundred feet. Note the Dallas has an application 
  64. note that describes the use of a 115kbps serial UART (i.e, a PC UART) to drive
  65. the one-wire interface. In that application, the pulse is more than 8 micro-
  66. seconds, which cuts the "guard time" to 6 microseconds or so.
  67.  
  68. The stamp will use one pin to send the control pulses and another to read the
  69. latch. The pin is connected to the inverted control pin of a tri-state driver.
  70. The driver's input is grounded and it's output connected to the one-wire. Thus,
  71. the stamp's TTL output pulse is converted into a "tri-state" pulse. 
  72.  
  73. In addition, the stamp's output pin is connected to the control pin of the one-
  74. shot so that the one-shot will change state at the start of the pulse. The one-
  75. shot's output pulse width is adjusted to a nominal 14 microseconds by selecting
  76. the appropriate values for the timing resistor and capacitor. The one-shot's 
  77. pulse output is connected to the latch control input of the latch, so the 
  78. trailing edge of the pulse causes the data to latch. The data input of the 
  79. latch is connected to the one-wire, and the output of the latch is connected to
  80. the stamp input pin. As a result, the latch will capture a sample of the one-
  81. wire's state 14 microseconds after the leading edge of each pulse generated by 
  82. the stamp. The Stamp's software will generate pulse trains. Some of the pulses
  83. will be reads, but most will not. The latch doesn't care: it will simply take a 
  84. sample 14microseconds after the start of each pulse. The software won't bother
  85. to read the latch unless the output pulse is a read. If the output pulse is a 
  86. read, the software will read the latch.
  87.  
  88. The resistor and capacitor that control the length of the one-shot can in 
  89. theory be any combination such that the resistance in ohms, times the 
  90. capacitance in farads, times the time constant of the '123 (1sec/(ohm*farad))
  91. equals the desired output pulse width of 14 microseconds. Since I know very 
  92. little about hardware design, I don't know whether not the 5.6Kohm times 2700pf
  93. is a good choice. As a wild guess, smaller resistance/larger capacitor will 
  94. draw more power but be more stable, and higher resistance/smaller capacitor
  95. will draw less power but be more stable. I simply picked a capacator out of my
  96. junk box, then picked a resistor to match, then measured the pulse and 
  97. adjusted. Since my ancient oscilloscope died and went to the great junk box in
  98. the sky, I used the stamp to measure the pulse width.  
  99.  
  100. Schematic 
  101.  
  102. (Adapted from a schematic supplied by Dave Kitts, who is another 
  103. STAMP experimenter.)
  104.  
  105. Hardware 
  106.  
  107.  
  108. 174HCT125quad tristate driver
  109. 174HCT123dual monostable flop
  110. 174HCT74 dual flip-flop
  111. 14.7Kohm resistor 
  112. 15.6Kohm resistor 
  113. 12700pF capacitor 
  114.  
  115. One quarter of the '125 and half of each of the other two ICs are used.
  116.  
  117. Detailed HW connections
  118.  
  119. '125
  120.  
  121. pin 1 enable* connect to STAMP hw pin 12
  122. pin 2 in. ground
  123. pin 3 out. Connect to one-wire, and to a pull-up. 
  124. Pin 7 ground.
  125. Pin 14 +5VDC
  126. pins 4-6 and 8-13 NC.
  127.  
  128. '123
  129.  
  130. pin 1 trigger. Connect to STAMP pin 11.
  131. Pin 2 "B" (pull hi)
  132. pin 3 reset. (pull hi)
  133. pin 4 neg out. Connect to '74 pin 3 
  134. pin 8 Ground
  135. pin 13 pos out. (nc)
  136. pin 14 C ext. connect to timing cap.
  137. Pin 15 Cext/Rext. Connect to timing cap and resistor
  138. Pin 16 +5VDC
  139. pins 5,6,7,9,10,11, 12 unused.
  140.  
  141. '74
  142.  
  143. pin 1 reset*. (pull hi)
  144. pin 2 input. Connect to one-wire
  145. pin 3 clock pulse. Connect to '123 pin 4
  146. pin 4 set* (pull hi)
  147. pin 5 pos out. Connect to stamp pin 11
  148. pin 6 neg out. (nc)
  149. pin 7 Ground
  150. pins 8-13 NC
  151. pin 14 +5VDC
  152.  
  153. Thermometer software 
  154.  
  155. the I/O control for the thermometers can be described as a "multi-level
  156. protocol". The lowest protocol level is the pulse level, which sends pulses
  157. of various lengths and receives responses. The next level is the byte I/O 
  158. level, which sends and receives 8-bit bytes. The next level is the "command"
  159. level, which sends and receives particular byte strings.
  160.  
  161. Pulse level 
  162.  
  163. This protocol level presents six "primitives" to the next protocol level: 
  164. Reset, Write 0, Write 1, Read bit, start CRC, and check CRC. In each case, the
  165. hardware latches the one-wire state and makes it available on the input pin, 
  166. but the higher-layer protocol only uses it when a read response is expected. 
  167. The pulse level interacts with the one-wire interface by sending PULSOUT
  168. commands to the output pin. The pulse level must therefore initialize the pin 
  169. to HIGH.
  170.  
  171. The pulse level maintains a running computation of the input CRC in a byte 
  172. variable. 
  173.  
  174. Reset: send a 600 microsecond pulse, then wait one millisecond. The dallas 
  175. devices respond to a "reset" with a "presence pulse", but the interface 
  176. hardware and software ignore it. The one-millisecond pause allows the presence
  177. pulses to finish.
  178. Write 0: send a 60 microsecond pulse.
  179. Write 1: send a 2 microsecond pulse. The protocol requires that the stamp leave
  180. the line high for 60 microseconds after this pulse. The code does nothing to 
  181. enforce this, but it happens anyway because it will take longer than this for 
  182. the code to get to the next pulse command.
  183. Read: send a 2 microsecond pulse. The interface will latch the result and 
  184. present it to the stamp input pin 14 microseconds after the beginning of the 
  185. pulse. Thus, the input is available in time for the next STAMP instruction 
  186. after the read. The read instruction uses this input value to update the 
  187. crcbyte.
  188. Start CRC: to start the CRC computation, the higher-level sets the crcbyte to
  189. zero.
  190. Check CRC: after receiving a valid string with a good CRC, the crcbyte will be
  191. zero.
  192.  
  193. Byte-level primitives 
  194.  
  195. Many of the higher-level functions of the protocol may be modelled as sending
  196. and receiving bytes. The routine to send a byte takes the byte in a variable 
  197. named "tbyte" and sends it as 8 bits. The routine to receive a byte places 8 
  198. bits into "tbyte". 
  199.  
  200. Command Level 
  201.  
  202. The Dallas protocol specifies a "transaction". A transaction has the following
  203. elements:
  204.  
  205.  - Initialization
  206.  - ROM function command
  207.  - Memory function command
  208.  - Transaction/Data 
  209.  
  210. The reset primitive is used for initialization. ROM functions 
  211.  
  212. There are five ROM functions in the protocol: read ROM, Match ROM, Skip ROM, 
  213. Search ROM, and Alarm Search. The code does not implement the Search ROM or the
  214. Alarm search, since they are of limited utility and they are very complex. Skip
  215. ROM is done by sending a single byte. Read ROM and Match ROM are more 
  216. complicated.
  217.  
  218. Read ROM: this subroutine sends the read rom command byte, starts the CRC, 
  219. reads eight bytes into the working buffer. CRC byte should be zero at the end
  220. of the subroutine.
  221. Match ROM: this subroutine sends the match ROM command byte, then sends an 8-
  222. byte ID for 1820 to be addressed. This routine operates in conjunction with a
  223. table of IDs in the STAMP's DATA memory. It sends the ID whose index number is
  224. in the idcnt variable.
  225.  
  226. Memory Commands 
  227.  
  228. There are several memory commands. The only one implemented for this 
  229. application is the "convert T" command. For this command, we send the command
  230. byte, then pause for 500 milliseconds. 
  231.  
  232. Computing The Temperature 
  233.  
  234. The 1820 returns a 16-bit temperature value with a granularity of .5 degree 
  235. centigrade.
  236.  
  237. It also returns a pair of numbers that represent the fraction of a degree and
  238. which can be used to refine the measurement. The coarse temperature is the 
  239. centigrade temperature in degrees, ignoring the LSB of the 16-bit value.
  240.  
  241.  TEMP=coarse_temp-0.25+(denom-num)/denom, or
  242.  
  243.  TEMP=coarse_temp+.75-num/denom
  244.  
  245. My application operates in Farenheit and needs higher precision, so I multiply
  246. the coarse temp by 180 to get hundredth's of a farenheit degree, then subtract
  247. 135 (1.35F =.75 C), then compute the fine-grain adjustment by multiplying the
  248. num by 180, dividing by the denom, then subtract fine-grain adjustment from the
  249. coarse farenheit. My application then adds 32 prior to displaying the result. 
  250.  
  251. "Parasite Power" Operation 
  252.  
  253. The interface can be adapted to support Dallas 1820's using parasite power. In
  254. this mode, the 1820's power pin is not connected, and the device draws up to 
  255. 5ma of power from the signal line during a "convert" or "ROM WRITE" command.
  256. After the master sends one of these commands, the master must begin supplying 
  257. power on the signal line within ten microseconds. The circuit described above 
  258. lets the stamp put the signal line in either of two states: Lo-impedance low
  259. voltage, (i.e., active logic zero), or hi-impedance logic hi (i.e., "tri-stated
  260. and pulled up".) Parasite power requires an additional state: lo-impedance 
  261. logic high. As it happens, the tri-state driver can do this. 
  262.  
  263. All that's necessary is to control the input pin of the tri-state driver. The 
  264. circuit described above has that pin grounded. To control the pin, simply 
  265. disconnect it from ground and connect it to an unused pin on the stamp. The 
  266. software described above will continue to operate normally when this new pin is
  267. driven low by the stamp. To provide parasite power, the "convert" or "ROM 
  268. WRITE" command is sent with a different software routine. This routine starts 
  269. by setting the new stamp pin to HIGH. It then sets the old control pin LOW. 
  270. Now, the circuit is actively driving the signal wire. Now the new routine sends
  271. pulses on the new pin to send the command. After the last pulse, the signal
  272. line will continue to be driven hi by the tri-state driver, which will supply
  273. enough power to satisfy the 1820. After the master finishes waiting for 
  274. completion of the command, it sets the old signal pin back to hi, and then sets
  275. the new signal pin to low, to revert to normal operation. The remainder of the
  276. software is unaffected.
  277.  
  278. Updated 12 Feb 96. This is version 3. 
  279.  
  280.